const mongoose = require('../common/db');

const chat = new mongoose.Schema({
  chatRoom: String, // 房间名称
  userOne: String, // 发件人
  userTwo: String, // 收件人
  imgOne: String, // 发件人头像
  imgTwo: String, // 收件人头像
  isRead: Boolean, // 是否查看
  chatContent: Array, // 聊天内容
  chatTime: String, // 聊天时间
});
// 通过用户名查找
chat.statics.findByUsername = function (username, callBack) {
  this.find({ '$or': [{ userOne: username }, { userTwo: username }] }, callBack);
};
// 通过房间名查找
chat.statics.findByRoom = function (chat_room, callBack) {
  this.findOne({ chatRoom: chat_room }, callBack);
};

const chatModel = mongoose.model('chat', chat);
module.exports = chatModel;